<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>配置管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../css/customer_list.css" media="all">
    <style>
        #roleAuthTable + .layui-table-view .layui-table tbody tr:hover {
            background-color: transparent;
        }
        .layui-form-item .layui-input-inline{
            width: 250px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">关键字</label>
                        <div class="layui-input-inline mr0">
                            <input id="search_word" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="btnReset" class="layui-btn layui-btn-warm"><i class="layui-icon">&#xe669;</i>重置
                        </button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="infoTable" lay-filter="infoTable"></table>
        </div>
    </div>
</div>
<!-- 表格操作列 -->
<script type="text/html" id="infoTableBar">
    <a class="layui-btn-a" lay-event="edit">修改</a>
</script>
<!-- 充值金额表单弹窗 -->
<script type="text/html" id="rechargeForm">
    <form lay-filter="rechargeForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label">充值金额</label>
            <div class="layui-input-block">
                <input name="money" placeholder="请输入充值金额" type="text" class="layui-input"
                       lay-verify="required|numberDh" required/>
            </div>
            <div class="layui-form-mid layui-word-aux" style="margin-left:100px ">
                <span style="color: red;">（多个充值金额用逗号（,）分隔）</span>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="rechargeFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>
<!-- 充值增加次数表单弹窗 -->
<script type="text/html" id="payCountForm">
    <form lay-filter="payCountForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label">充值金额</label>
            <div class="layui-input-inline">
                <input name="money" value="0" placeholder="请输入充值金额" type="number" class="layui-input" lay-verify="required|number|positiveNumber"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">增加次数</label>
            <div class="layui-input-inline">
                <input name="times" placeholder="请输入增加次数" type="number" class="layui-input"
                       lay-verify="required|number|wholeNumber" required/>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="payCountFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>
<!-- 充值增加次数表单弹窗 -->
<script type="text/html" id="shareCountForm">
    <form lay-filter="shareCountForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px;">增加访问次数</label>
            <div class="layui-input-inline">
                <input name="times" placeholder="请输入增加访问次数" type="number" class="layui-input"
                       lay-verify="required|number|wholeNumber" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px;">每天可分享次数</label>
            <div class="layui-input-inline">
                <input name="one_day_share_times" placeholder="请输入可分享次数" type="number" class="layui-input"
                       lay-verify="required|number|wholeNumber" required/>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="shareCountFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>
<!--新用户-->
<script type="text/html" id="addUserCountForm">
    <form lay-filter="addUserCountForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px;">增加访问次数</label>
            <div class="layui-input-inline">
                <input name="times" placeholder="请输入增加访问次数" type="number" class="layui-input"
                       lay-verify="required|number|wholeNumber" required/>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addUserCountFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--间隔时间算访问次数-->
<script type="text/html" id="browseIntervalTimesForm">
    <form lay-filter="browseIntervalTimesForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px;">间隔时间</label>
            <div class="layui-input-inline">
                <input name="times" placeholder="请输入间隔时间" type="number" class="layui-input"
                       lay-verify="required|number|wholeNumber" required/>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span style="color: red;">（小时）</span>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="browseIntervalTimesFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--间隔时间算访问次数-->
<script type="text/html" id="deadlineForm">
    <form lay-filter="deadlineForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 150px;">供货商到期前多久提醒</label>
            <div class="layui-input-inline">
                <input name="content" placeholder="请输入" type="number" class="layui-input"
                       lay-verify="required|number" required/>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="deadlineFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--间隔时间算访问次数-->
<script type="text/html" id="editForm">
    <form lay-filter="editForm" class="layui-form model-form">
        <input name="name" hidden/>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px;" id="title_name"></label>
            <div class="layui-input-inline">
                <input name="content" placeholder="请输入" type="number" class="layui-input"
                       lay-verify="required|number" required/>
            </div>
            <div class="layui-form-mid layui-word-aux">%</div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="editFormSubmit" type="button" lay-submit>保存</button>
        </div>
    </form>
</script>

<script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../common/layui/layui2.js"></script>
<script type="text/javascript" src="../../js/main.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'table','admin', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var config = layui.config;

        form.render();
        // 渲染表格
        table.render({
            elem: '#infoTable',
            url: access_baseurl+'Config/getList.html',
            method:'POST',
            where: {
                basic:1
            },
            page: true,
            cellMinWidth: 80,
            id:'infoTable',
            limits:[15,30,45,60],
            limit:15,
            cols: [[
                {align: 'center',field: 'common',title: '配置项'},
                {align: 'center',title: '配置信息',
                    templet:function (d) {
                        if(['tax','profit_rate'].indexOf(d.name) !== -1){
                            return d.val.content+'%';
                        }else if(d.name === 'show_notice_day'){
                            return d.val.content+'天';
                        }else{
                            return d.val.content
                        }
                    }},
                {align: 'left',toolbar: '#infoTableBar',title: '操作',width:100}
            ]],
            done: function (res, curr, count) {
            }

        });

        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            var where = getWhere();
            table.reload('infoTable', {where: where});
        });

        $('#btnReset').click(function () {
            $('#search_word').val('');
            form.render();
            var where = getWhere();
            table.reload('infoTable', {where:where});
        });

        // 工具条点击事件
        table.on('tool(infoTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            data.val.name = data.name
            if(layEvent === 'edit'){
                if(['tax','profit_rate'].indexOf(data.name) !== -1){
                    showEditModel(data)
                }else if(data.name === "show_notice_day"){
                    showEditDeadlineFormModel(data)
                }
            }
        });

        function getWhere() {
            var search_word = $('#search_word').val();
            var where = {
                search_word:search_word,
            };
            return where;
        }
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '600px',
                offset: '65px',
                title: '设置'+data.common,
                content: $('#editForm').html(),
                success: function (layero, index) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    $('#title_name').html(data.common);
                    form.render();
                    if (data) {
                        form.val('editForm', data.val);
                        form.render();
                    }
                }
            });
        }
        form.on('submit(editFormSubmit)', function (d) {
            submitInfo(d.field)
        });
        // 表单提交
        function showEditDeadlineFormModel(data) {
            admin.open({
                type: 1,
                area: '600px',
                offset: '65px',
                title: '设置'+data.common,
                content: $('#deadlineForm').html(),
                success: function (layero, index) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    if (data) {
                        form.val('deadlineForm', data.val);
                    }
                    form.render();
                }
            });
        }
        form.on('submit(deadlineFormSubmit)', function (d) {
            submitInfo(d.field)
        });

        function submitInfo(info){
            var data = {};
            data.name= info.name;
            Reflect.deleteProperty(info, 'name');
            data.val= JSON.stringify(info);
            send_req('Config/modify', data, function (data) {
                layer.msg('设置成功', {icon: 1},function () {
                    layer.closeAll('loading');
                    layer.closeAll('page');
                    table.reload('infoTable');
                });
            });
            return false;
        }
        form.verify({
            numberDh: function(value, item){
                var reg = /^[0-9]+(,[0-9]+)*$/; // 正则表达式，匹配数字和逗号
                if(!reg.test(value)){
                    return '请输入正确的金额';
                }
            },
            positiveNumber:[/^(([0-9]+[\.]?[0-9]+)|[1-9])$/,'请输入正确的金额'],
            wholeNumber:[/^[+]{0,1}(\d+)$/,'请输入正确的数字'],
        });
    });
</script>
</body>
</html>